package com.czumi.javawx.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import com.czumi.javawx.dao.entity.WeixinGroup;
import com.czumi.javawx.dao.repository.WeixinGroupRepository;

@Service
public class WeixinGroupService {

	@Autowired
	private WeixinGroupRepository weixinGroupRepository;

	@CacheEvict(value="spaj" ,key="'WeixinGroup'")  
	public void saveAndUpdate(WeixinGroup weixinGroup) {
		WeixinGroup searchT = new WeixinGroup();
		searchT.setGroupId(weixinGroup.getGroupId());
		Example<WeixinGroup> example = Example.of(weixinGroup);
		WeixinGroup ret = weixinGroupRepository.findOne(example);
		if (ret != null) {
			weixinGroup.setId(ret.getId());
		}
		weixinGroupRepository.saveAndFlush(weixinGroup);

	}

	@Cacheable(value="spaj" ,key="'WeixinGroup'") 
	public List<WeixinGroup> getAllWeixinGroup() {
		return weixinGroupRepository.findAll();
	}
}
